#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main(int argc, char* argv[])
{
    struct timeval tv;
    gettimeofday(&tv, NULL);

    system("date");
    printf("current timeval : %lu:%06lu.\n", tv.tv_sec, tv.tv_usec);

    char* str = argv[1];
    if(str[0] == '+') {
        tv.tv_sec += atol(str+1); 
        tv.tv_usec = 0;
        printf("add %ld seconds.\n", atol(str+1));
    }

    if(str[0] == '-') {
        tv.tv_sec -= atol(str+1); 
        tv.tv_usec = 0;
        printf("sub %ld seconds.\n", atol(str+1));
    }

    if(str[0] == 's') {
        tv.tv_sec = atol(str+1); 
        tv.tv_usec = 0;
        printf("set %ld seconds.\n", atol(str+1));
    }

    if(str[0] == 'r') {
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC, &ts);
        tv.tv_sec = ts.tv_sec;
        tv.tv_usec = ts.tv_nsec / (long)1000;
        printf("resume to mono time.\n");
    }

    settimeofday(&tv, NULL);

    system("date");
    printf("current timeval : %lu:%06lu.\n", tv.tv_sec, tv.tv_usec);

    return 0;
}
